<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>#{bundle_partners_vi.Title}</title>
        <script>
            function confirmComplete() {
                var answer = confirm("Bạn có chắc chắn muốn xóa bản ghi này?");
                if (answer == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        </script>
    </h:head>
    <h:body> 
        <link type="text/css" rel="stylesheet" href="../css/main.css" />        
        <style type="text/css">
            .ui-widget{font-size:95% !important;}
            .ui-layout-unit-content{background-color: #E5E5E5;border-width: 0px}              
            .ui-widget{border-width: 0px;color: red}
        </style>
        <div align="center" id="bodyForm" >            
            <div style="width: 100%;">
                <p:layoutUnit id="top" position="north" size="auto">
                    <ui:insert name="menu">
                        <ui:include src="../../templates/menu.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
                <p:layoutUnit id="center" position="center" size="400">
                    <h1 class="headerbar">#{bundle_partners_vi.Title}</h1>
                    <p:outputPanel id="pnP" style="width: 100%;background-color: #E5E5E5">
                        <p:growl id="message"/>
                        <p:panel>
                            <h:form id="form" style="width: 100%;">                                
                                <p:dialog modal="true" widgetVar="statusDialog" header="#{bundle_partners_vi.Searching}"   
                                          draggable="false" closable="false">  
                                    <p:graphicImage value="../../images/ajax-loader.gif" />  
                                </p:dialog>
                                <div align="center" style="margin-top: 10px;margin-bottom: 10px;margin-left: 10px;">
                                    <h:outputText value="#{bundle_partners_vi.Name}: "/><p:inputText value="#{partnerController.nameS}"/><p:commandButton icon="ui-icon ui-icon-search" value="#{bundle_partners_vi.Search}" action="#{partnerController.search()}" update=":pnP" onclick="statusDialog.show();" oncomplete="statusDialog.hide();"/>
                                    <p:commandButton value="#{bundle_partners_vi.Add}" onclick="dlgAdd.show()" icon="ui-icon ui-icon-plusthick" update=":formAdd" action="#{partnerController.updateInsert()}"/>
                                </div>
                            </h:form>
                        </p:panel>
                        <p:panel>
                            <h:form style="width: 100%" id="form2">
                                <p:panel header="#{bundle_partners_vi.HeaderContTem}" id="pnltree">
                                    <p:dataTable id="tblSys" 
                                                 var="i" 
                                                 value="#{partnerController.items}"
                                                 rowKey="#{i.id}"                                                                                                 
                                                 style="width: 100%;" paginator="true" rows="10">
                                        <p:column headerText="#{bundle_partners_vi.Id}">
                                            <h:outputText value="#{i.id}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_partners_vi.Code}">
                                            <h:outputText value="#{i.code}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_partners_vi.Name}">
                                            <!--<h:outputText value="#{i.name}" style="float: right;"/>-->
                                            <p:commandLink value="#{i.name}" style="float: right;" action="#{partnerController.updateToDlgP()}" onclick="dlgProducts.show();statusDialog.show()" oncomplete="statusDialog.hide()" update=":formP"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_partners_vi.Status}">
                                            <h:outputText value="#{i.status eq 1 ? bundle_partners_vi.Status1:bundle_partners_vi.Status0}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_partners_vi.CreateDate}">
                                            <h:outputText value="#{i.createDate}" style="float: right;"/>
                                        </p:column>

                                        <p:column headerText="#{bundle_partners_vi.Edit}" style="width: 10px">
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgEdit.show()" update=":formEdit" actionListener="#{partnerController.updateDlgEdit()}"/>
                                            </div>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.Delete}" style="width: 10px">                                            
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="return confirmComplete()" update=":pnP" action="#{partnerController.remove()}"/>
                                            </div>
                                        </p:column>
                                    </p:dataTable>                                    
                                </p:panel>
                            </h:form>   
                        </p:panel>
                        <!--dialog them add-->
                        <p:dialog modal="true" widgetVar="dlgAdd" header="#{bundle_partners_vi.HeaderDlgAdd}" resizable="false">
                            <h:form style="width: 100%" id="formAdd">
                                <p:growl id="message1"/>
                                <h:panelGrid columns="2">
                                    <h:outputText value="#{bundle_partners_vi.Code}: "/> <p:inputText value="#{partnerController.current.code}"/>
                                    <h:outputText value="#{bundle_partners_vi.Name}: "/> <p:inputText value="#{partnerController.current.name}"/>
                                    <h:outputText value="#{bundle_partners_vi.Status}: "/> 
                                    <p:selectOneMenu value="#{partnerController.current.status}" >
                                        <f:selectItem itemValue="1" itemLabel="#{bundle_partners_vi.Status1}"/>
                                        <f:selectItem itemValue="0" itemLabel="#{bundle_partners_vi.Status0}"/>
                                    </p:selectOneMenu>
                                    <h:outputText value=""/>
                                    <h:panelGrid columns="2">
                                        <p:commandButton value="#{bundle_partners_vi.Save}" style="width: 60px" action="#{partnerController.insert()}" update=":pnP"/>
                                    </h:panelGrid>
                                </h:panelGrid>
                            </h:form>
                        </p:dialog>
                        <!--dialog edit-->
                        <p:dialog modal="true" widgetVar="dlgEdit" header="#{bundle_partners_vi.HeaderDlgEdit}" resizable="false" >
                            <h:form style="width: 100%" id="formEdit">
                                <p:growl id="message1"/>
                                <h:panelGrid columns="2">
                                    <h:outputText value="#{bundle_partners_vi.Id}: " style="display: none"/> <p:inputText value="#{partnerController.current.id}" style="display: none"/>
                                    <h:outputText value="#{bundle_partners_vi.Code}: "/> <p:inputText value="#{partnerController.current.code}"/>
                                    <h:outputText value="#{bundle_partners_vi.Name}: "/> <p:inputText value="#{partnerController.current.name}"/>
                                    <h:outputText value="#{bundle_partners_vi.Status}: "/> 
                                    <p:selectOneMenu value="#{partnerController.current.status}" >
                                        <f:selectItem itemValue="1" itemLabel="#{bundle_partners_vi.Status1}"/>
                                        <f:selectItem itemValue="0" itemLabel="#{bundle_partners_vi.Status0}"/>
                                    </p:selectOneMenu>
                                    <h:outputText value=""/>
                                    <h:panelGrid columns="2">
                                        <p:commandButton value="#{bundle_partners_vi.Save}" style="width: 60px" action="#{partnerController.update()}" update=":pnP"/>
                                    </h:panelGrid>                                    
                                </h:panelGrid>
                            </h:form>
                        </p:dialog>
                        <!--dialog edit Product Partner (PP)-->
                        <p:dialog modal="true" widgetVar="dlgEditPP" header="#{bundle_partners_vi.HeaderDlgEditPP}" resizable="false" >
                            <h:form style="width: 100%" id="formEditPP">
                                <p:growl id="message1PP"/>
                                <h:panelGrid columns="2">
                                    <h:outputText value="Id: "/> <h:outputText value="#{partnerController.currentPP.id}"/>
                                    <h:outputText value="#{bundle_partners_vi.NameP}: "/><h:outputText value="#{partnerController.currentPP.productName}"/>
                                    <h:outputText value="#{bundle_partners_vi.StartDate}: "/><p:calendar pattern="dd-MM-yyyy" showOn="button" value="#{partnerController.currentPP.SDate}"/>
                                    <h:outputText value="#{bundle_partners_vi.EndDate}: "/><p:calendar pattern="dd-MM-yyyy" showOn="button" value="#{partnerController.currentPP.EDate}"/>
                                    <h:outputText value=""/>
                                    <h:panelGrid columns="2">
                                        <p:commandButton value="#{bundle_partners_vi.Save}" style="width: 60px" action="#{partnerController.editPP()}" update=":formP" oncomplete="dlgEditPP.hide();statusDialog2.hide()" onclick="statusDialog2.show()"/>
                                    </h:panelGrid>                                    
                                </h:panelGrid>
                            </h:form>
                        </p:dialog>
                        <!--dialog products-->
                        <p:dialog modal="true" widgetVar="dlgProducts" header="#{bundle_partners_vi.HeaderDlgProducts}" resizable="false" id="dlgP">
                            <h:form style="width: 800px;height: 600px" id="formP">
                                <p:growl id="messageP"/>
                                <p:panel header="Danh sách Product của #{partnerController.current.name}">
                                    <p:dataTable id="tbl" 
                                                 var="p" 
                                                 value="#{partnerController.partnerProduct}"
                                                 rowKey="#{p.id}"                                                                                                 
                                                 style="width: 100%;" paginator="true" rows="5" paginatorPosition="bottom"> 
                                        <p:column headerText="Id">
                                            <h:outputText value="#{p.id}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.NameP}">
                                            <h:outputText value="#{p.productName}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.StartDate}">
                                            <h:outputText value="#{p.startDate}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.EndDate}">
                                            <h:outputText value="#{p.endDate}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.Edit}" style="width: 10px">
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgEditPP.show()" update=":formEditPP" actionListener="#{partnerController.updateDlgEditPP()}"/>
                                            </div>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.Delete}" style="width: 10px">                                            
                                            <div align="center">
                                                <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="dlgDelPP.show()" update=":formDelPP" actionListener="#{partnerController.updateDelPP()}"/>
                                            </div>
                                        </p:column>
                                    </p:dataTable>
                                </p:panel>
                                <p:panel header="#{bundle_partners_vi.AllP}">
                                    <h:panelGrid columns="2" style="width: 100%">
                                        <p:dataTable id="tblP" 
                                                     var="p" 
                                                     value="#{partnerController.allProduct}"
                                                     rowKey="#{p.id}"                                                                                                 
                                                     style="width: 100%;" paginator="true" rows="10" paginatorPosition="bottom"
                                                     selection="#{partnerController.listPPInsert}">
                                            <p:column selectionMode="multiple" style="width:2%" disabledSelection="#{not p.status}"/> 

                                            <p:column headerText="#{bundle_partners_vi.IdP}">
                                                <h:outputText value="#{p.id}"/>
                                            </p:column>
                                            <p:column headerText="#{bundle_partners_vi.NameP}">
                                                <h:outputText value="#{p.name}"/>
                                            </p:column>
                                            <p:column headerText="#{bundle_partners_vi.RegKey}">
                                                <h:outputText value="#{p.regKeyword}"/>
                                            </p:column>
                                        </p:dataTable>
                                    </h:panelGrid>
                                    <p:commandButton value="#{bundle_partners_vi.Update}" onclick="dlgInsertPP.show()" update=":formPP"/>
                                </p:panel>
                            </h:form>
                        </p:dialog>
                        <!--dialog insert products for partners-->
                        <p:dialog modal="true" widgetVar="dlgInsertPP" header="#{bundle_partners_vi.HeaderDlgPP}" resizable="false" id="dlgPP">                            
                            <h:form style="width: 800px;height: 600px" id="formPP">
                                <p:growl id="messagePP"/>
                                <p:panel header="Danh sách Product đã chọn">
                                    <p:dataTable id="tblPP" 
                                                 var="p" 
                                                 value="#{partnerController.listPPInsert}"
                                                 rowKey="#{p.id}"                                                                                                 
                                                 style="width: 100%;" paginator="true" rows="5" paginatorPosition="bottom"> 
                                        <p:column headerText="Id">
                                            <h:outputText value="#{p.id}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.NameP}">
                                            <h:outputText value="#{p.name}"/>
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.StartDate}">
                                            <p:calendar pattern="dd-MM-yyyy" showOn="button" value="#{p.startDate}"/>                                                                                            
                                        </p:column>
                                        <p:column headerText="#{bundle_partners_vi.EndDate}">
                                            <p:calendar pattern="dd-MM-yyyy" showOn="button" value="#{p.endDate}"/>
                                        </p:column>
                                    </p:dataTable>       
                                    <br/>
                                    <p:commandButton value="#{bundle_partners_vi.Update}" action="#{partnerController.updatePP()}" update=":formPP :formP" oncomplete="dlgInsertPP.hide();statusDialog2.hide()" onclick="statusDialog2.show()"/>            
                                </p:panel>                               
                            </h:form>
                        </p:dialog>
                        <!--dialog delete PP-->
                        <p:dialog modal="true" widgetVar="dlgDelPP" header="#{bundle_partners_vi.HeaderDlgDelPP}" resizable="false" id="dlgDelPPId">                            
                            <h:form id="formDelPP">
                                <p:growl id="messageDelPP"/>
                                <h:outputText value="Bạn có chắc chắn xóa bản ghi này? Id: #{partnerController.currentPP.id}"/>
                                <p:commandButton value="#{bundle_partners_vi.Delete}" action="#{partnerController.removePP()}" oncomplete="statusDialog2.hide();dlgDelPP.hide()" onclick="statusDialog2.show()" update=":formP"/>                                            
                            </h:form>
                        </p:dialog>
                        <!--status dialog 2-->
                        <p:dialog modal="true" widgetVar="statusDialog2" header="#{bundle_partners_vi.Processing}"   
                                      draggable="false" closable="false">  
                                <p:graphicImage value="../../images/ajax-loader.gif" />  
                            </p:dialog>
                    </p:outputPanel>
                </p:layoutUnit>
                <p:layoutUnit id="bottom" position="bottom" size="60">
                    <ui:insert name="footer">
                        <ui:include src="../../templates/footer.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
            </div>
        </div>
    </h:body>
</html>

